#include "ofxIRCLineBuffer.h"
#include <iostream>
ofxIRCLineBuffer::ofxIRCLineBuffer() {
	buffer.resize(1024);
}

void ofxIRCLineBuffer::append(char* pBuf, int nSize) {
	for(int i = 0; i < nSize; ++i) {
		buffer.push_back(pBuf[i]);
	}
}

void ofxIRCLineBuffer::parse() {
	std::string line = "";
	int last = 0;
	for(int i = 0; i < buffer.size(); ++i) {
		if (buffer[i] == '\r' && buffer[i+1] == '\n' &&line.size() > 0) {
			lines.push_back(line);
			line.clear();
			last = i;
			continue;
		}
		line.push_back(buffer[i]);
	}
	if (last > 0) {
		buffer.erase(buffer.begin(), buffer.begin()+last);
	}
}

void ofxIRCLineBuffer::clear() {
	lines.clear();
}

std::vector<std::string> ofxIRCLineBuffer::getLines() {
	return lines;
}

